package com.lbmb.mdps.settings.service.impl;

import com.lbmb.mdps.commons.domain.CityVo;
import com.lbmb.mdps.commons.domain.ProvinceVo;
import com.lbmb.mdps.settings.dao.CityDao;
import com.lbmb.mdps.settings.dao.ProvinceDao;
import com.lbmb.mdps.settings.domain.City;
import com.lbmb.mdps.settings.domain.Province;
import com.lbmb.mdps.settings.service.ProvinceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 林文塨
 * @date 2022-05-30 11:15
 * description
 */
@Service("provinceService")
public class ProvinceServiceImpl implements ProvinceService {

    @Resource
    private CityDao cityDao;
    @Resource
    private ProvinceDao provinceDao;

    @Override
    public List<ProvinceVo> getAllProvinceVo() {
        /*
         * 获得省市二级表
         * @author 林文塨
         * @date 2022/5/30 11:15
         * @param []
         * @return java.util.List<com.lbmb.mdps.commons.domain.ProvinceVo>
         */
        List<ProvinceVo> provinceVoList = new ArrayList<>();

        List<Province> provinceList = provinceDao.getAllProvince();

        /*查省*/
        for (Province province : provinceList) {

            List<CityVo> cityVoList = new ArrayList<>();

            ProvinceVo provinceVo = new ProvinceVo();
            provinceVo.setLabel(province.getName());
            provinceVo.setValue(province.getName());

            /*查市*/
            List<City> cityList = cityDao.getAllCityByProvince(province);

            for (City city : cityList) {
                CityVo cityVo = new CityVo();
                cityVo.setLabel(city.getName());
                cityVo.setValue(city.getName());

                cityVoList.add(cityVo);
            }

            provinceVo.setChildren(cityVoList);

            provinceVoList.add(provinceVo);
        }

        return provinceVoList;
    }
}
